<template>
  <div>
    <div style="margin:10px;padding:0 20px;background:#fff;">
        <a-tabs v-model:activeKey="activeKey">
         <a-tab-pane key="1" tab="出入记录">
              <BasicTable @register="registerTable">
                <template #tableTitle>
                    <a-button  type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
                </template>
                <template v-slot:bodyCell="{ column, record, index, text }">
                </template>
                  <template #img="{ text }">
                    <img style="cursor: pointer;" @click="PreImg(baseApiUrl+'/'+VITE_GLOB_BUCKET_NAME+'/'+text)" :src="baseApiUrl+'/'+VITE_GLOB_BUCKET_NAME+'/'+text" width="50px" height="50px" v-show="text"/>
                  </template>
              </BasicTable>
          </a-tab-pane>
          <a-tab-pane key="3" tab="陌生人记录">
                <AtrangerRecord></AtrangerRecord>
           </a-tab-pane>
          <a-tab-pane key="2" tab="统计">
                <AcAccessRecordTotal></AcAccessRecordTotal>
          </a-tab-pane>
         
        </a-tabs>
    </div>
 
   <!-- <BasicTable @register="registerTable" >
      <template #tableTitle>
          <a-button  type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
      </template>
      <template v-slot:bodyCell="{ column, record, index, text }">
      </template>
    </BasicTable> -->
    <!-- 表单区域 -->
    <!-- <AcAccessRecordModal @register="registerModal" @success="handleSuccess"></AcAccessRecordModal> -->
  </div>
</template>

<script lang="ts" name="acaccessrecord-acAccessRecord" setup>
  import {ref, reactive, computed, unref} from 'vue';
  import {BasicTable, useTable, TableAction} from '/@/components/Table';
  import {useModal} from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage'
  import AcAccessRecordModal from './components/AcAccessRecordModal.vue'
  import AcAccessRecordTotal from './components/AcAccessRecordTotal.vue'
  import AtrangerRecord from './components/AtrangerRecord.vue'
  import {columns, searchFormSchema, superQuerySchema} from './AcAccessRecord.data';
  import {totalList,list, deleteOne, batchDelete, getImportUrl,getExportUrl} from './AcAccessRecord.api';
  import { downloadFile } from '/@/utils/common/renderUtils';
  import { useUserStore } from '/@/store/modules/user';
  import {useGlobSetting} from "@/hooks/setting";
  import {getAppEnvConfig} from "@/utils/env";
  import { createImgPreview } from '/@/components/Preview/index';

  const queryParam = reactive<any>({});
  const checkedKeys = ref<Array<string | number>>([]);
  const userStore = useUserStore();
  let activeKey = ref('1')
  const globSetting = useGlobSetting();
  const {VITE_GLOB_BUCKET_NAME} = getAppEnvConfig();
  const baseApiUrl = globSetting.domainUrl;
  //注册model
  const [registerModal, {openModal}] = useModal();
  //注册table数据
  const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({
      tableProps:{
           title: '出入记录',
           api: list,
           columns,
           canResize:false,
           showActionColumn: false,
           formConfig: {
              //labelWidth: 120,
              schemas: searchFormSchema,
              autoSubmitOnEnter:true,
              showAdvancedButton:true,
              fieldMapToNumber: [
              ],
              fieldMapToTime: [
                 ['accessDate', ['accessDate_begin', 'accessDate_end'], 'YYYY-MM-DD'],
              ],
            },
           actionColumn: {
               width: 120,
               fixed:'right'
            },
            beforeFetch: (params) => {
              return Object.assign(params, queryParam);
            },
      },
       exportConfig: {
            name:"出入记录",
            url: getExportUrl,
            params: queryParam,
          },
          importConfig: {
            url: getImportUrl,
            success: handleSuccess
          },
  })
  const isorter={
      column:'accessDate',
      order:'asc'
  }
  const [registerTable, {reload},{  }] = tableContext

  // 高级查询配置
  const superQueryConfig = reactive(superQuerySchema);

  function PreImg(val){
      createImgPreview({ imageList: [val], maskClosable: true });
  }
  /**
   * 高级查询事件
   */
  function handleSuperQuery(params) {
    Object.keys(params).map((k) => {
      queryParam[k] = params[k];
    });
    reload();
  }
   /**
    * 新增事件
    */
  function handleAdd() {
     openModal(true, {
       isUpdate: false,
       showFooter: true,
     });
  }
   /**
    * 编辑事件
    */
  function handleEdit(record: Recordable) {
     openModal(true, {
       record,
       isUpdate: true,
       showFooter: true,
     });
   }
   /**
    * 详情
   */
  function handleDetail(record: Recordable) {
     openModal(true, {
       record,
       isUpdate: true,
       showFooter: false,
     });
   }
   /**
    * 删除事件
    */
  async function handleDelete(record) {
     await deleteOne({id: record.id}, handleSuccess);
   }
   /**
    * 批量删除事件
    */
  async function batchHandleDelete() {
     await batchDelete({ids: selectedRowKeys.value}, handleSuccess);
   }
   /**
    * 成功回调
    */
  function handleSuccess() {
      (selectedRowKeys.value = []) && reload();
   }
   /**
      * 操作栏
      */
  function getTableAction(record){
       return [
         {
           label: '编辑',
           onClick: handleEdit.bind(null, record),
         }
       ]
   }
     /**
        * 下拉操作栏
        */
  function getDropDownAction(record){
       return [
         {
           label: '详情',
           onClick: handleDetail.bind(null, record),
         }, {
           label: '删除',
           popConfirm: {
             title: '是否确认删除',
             confirm: handleDelete.bind(null, record),
             placement: 'topLeft',
           }
         }
       ]
   }


</script>

<style scoped>

</style>
